Repository navigation
Fixes #38561: count no failed rows for a passing == custom SQL test - #38607
mayuriphad wants to merge 8 commits into
Conversation
…om SQL test A tableCustomSQLQuery test with operator == that passed counted the query's rows as passed and the rest of the table as failed, so == 0 reported 100% failed rows on success. A passing == test has no row in excess of the threshold, which is what the failure path counts, so it now reports the whole table as passed. Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
…equal-passed-rows Signed-off-by: mayuriphad <mayuriphad656@gmail.com> # Conflicts: # ingestion/src/metadata/data_quality/validations/table/base/tableCustomSQLQuery.py
…n a non-empty dataset The pandas empty-dataset test still asserted the old counts (passed=0, failed=3) for a passing == 0 on a three-row table, which is the behaviour this PR fixes.
…ssing == custom SQL test The rows a custom SQL query returns are the rows that break the rule, and they are the rows the failed rows sample stores. A passing == now counts them the way < and <= already do: failed = returned rows, passed = the rest. A passing == 0 still reports every row passed and none failed.
| passed_rows = len_rows | ||
| failed_rows = (row_count - len_rows) if row_count else 0 | ||
| elif operator in ("<", "<="): | ||
| elif operator in ("<", "<=", "=="): |
There was a problem hiding this comment.
The failing == path still inverts the counts when the query returns fewer rows than the threshold: _calculate_equal_failure sets failed_rows = row_count - len_rows. E.g. == 10, 5 rows returned, 1000-row table → 995 failed.
There was a problem hiding this comment.
Fixed in fdb2c07: _calculate_equal_failure now counts abs(len_rows - threshold) as failed and the rest of the table as passed, so == 10 with 5 rows on a 1000-row table gives 5 failed and 995 passed. The row-count and empty-dataset tests are updated for both sides of the threshold (64 passed locally).
…tance from the expected count A failing == that returned fewer rows than expected counted every row it did not return as failed (== 10 with 5 rows returned on a 1000-row table reported 995 failed). The failed rows are now the rows the result is off by, above or below the expected count, as the more-rows branch, the percentage test and the no-row-count fallback already counted them. A passing == is exactly on the expected count, so it reports no failed rows again.
| failed_rows = abs(len_rows - threshold) | ||
| passed_rows = (row_count - failed_rows) if row_count else 0 | ||
|
|
||
| return max(0, passed_rows), max(0, failed_rows) |
There was a problem hiding this comment.
💡 Edge Case: == failure can report more failed rows than the table has (>100%)
_calculate_equal_failure now sets failed_rows = abs(len_rows - threshold) without a cap. When the expected count is larger than the table (e.g. == 10 on a 5-row table and the query returns 3 rows), you get failedRows = 7 and passedRows = 0. get_test_case_result_object divides by row_count, so failedRowsPercentage comes out as 140%. Before this change, the fewer-rows branch used row_count - len_rows, which never went above the table size. The fix is to cap failed_rows at row_count when a row count is available.
Cap failed rows at the table row count:
failed_rows = abs(len_rows - threshold)
if row_count:
failed_rows = min(failed_rows, row_count)
passed_rows = row_count - failed_rows
else:
passed_rows = 0
return max(0, passed_rows), max(0, failed_rows)
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
Code Review 👍 Approved with suggestions 🟡 Medium risk 1 closed / 2 findingsChanging equality custom-SQL row accounting may misstate passed/failed row counts for successful or failed checks, affecting interpretation of data-quality results. Fixes passing 💡 Edge Case: == failure can report more failed rows than the table has (>100%)📄 ingestion/src/metadata/data_quality/validations/table/base/tableCustomSQLQuery.py:280-283
Cap failed rows at the table row count✅ 1 closed✅ Edge Case: Passing
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source
IceS2
left a comment
There was a problem hiding this comment.
Hey @mayuriphad, added a small comment. Can you please check it and check the gitar bot one?
Thanks a lot for the contribution
| # == counts how far the result is from the expected count as failed (see | ||
| # _calculate_equal_failure); a pass is exactly on it, so no row failed. | ||
| passed_rows = row_count if row_count else len_rows | ||
| failed_rows = 0 |
There was a problem hiding this comment.
Could we count the query matches as failed rows on a passing == check, as we do for <=?
With 10 matches on a 20-row table, == 10 should still succeed and report 10 passed / 10 failed.
Describe your changes:
Fixes #38561
When a
tableCustomSQLQuerytest with operator==passed,_calculate_passed_rows_successcounted the rows the query returned as passed and every other row in the table as failed. The common setup, where the query returns the offending rows and== 0are expected, therefore reportedpassedRows = 0andfailedRows = <row count>(100% failed) on aSuccessresult.This was also inconsistent with the
==failure path, which counts the rows in excess of the threshold as failed (len_rows - threshold). A passing==test has no excess, so it now reportsfailedRows = 0andpassedRows = row_count(orlen_rowswhen no row count is available). The>/>=/</<=branches and all failure paths are unchanged.Type of change:
High-level design:
N/A — small change.
Tests:
Use cases covered
== 0passing on a 1000-row table (the issue's scenario): 1000 passed, 0 failed.== 10passing with 10 returned rows: 1000 passed, 0 failed (previously asserted 10 / 990).Unit tests
ingestion/tests/unit/observability/data_quality/validations/test_table_custom_sql_query_row_counts.py. Both cases fail onmainand pass with the fix. All 64 tests intest_table_custom_sql_query*.pypass locally. On Windows, the sqlite-backed percentage tests also hitWinError 32errors in teardown that have nothing to do with this change.Backend integration tests
Ingestion integration tests
Playwright (UI) tests
Manual testing performed
ruff format --checkpasses on both files.UI screen recording:
Not applicable — data quality validator fix, no UI change.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.